//
//  WeatherSecondScrollView.m
//  weather
//
//  Created by 大L君的无敌战舰 on 16/4/12.
//  Copyright © 2016年 bigL.com. All rights reserved.
//

#import "BLScrollViewForWeatherSecondView.h"
#import "BLButtonForWeatherSecondScrollView.h"

@interface BLScrollViewForWeatherSecondView ()
/* 保存btn模型 */
@property (strong, nonatomic) NSMutableArray * btnArray;
/* 创建容器View */
@property (strong, nonatomic) UIView *containView;
@end

@implementation BLScrollViewForWeatherSecondView

-(NSMutableArray *)btnArray
{
    if (!_btnArray) {
        _btnArray = [NSMutableArray array];
    }
    return _btnArray;
}

//初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //当前View的配置信息
        [self selfConfigurationInformation];
        //加载子控件
        [self setChildView];
    }
    return self;
}

//当前View的配置信息
- (void)selfConfigurationInformation
{
    //设置内边距
    self.contentSize = CGSizeMake(BLScreenSize.width / 6 * 16, 0);
    //设置背景颜色
    self.backgroundColor = [UIColor clearColor];
    //隐藏滑动条
    self.showsVerticalScrollIndicator = NO;
    self.showsHorizontalScrollIndicator = NO;
    //关闭弹簧效果
    //self.bounces = NO;
}


-(void)setChildView
{
    //创建容器View
    UIView *containView = [[UIView alloc]init];
    self.containView = containView;
    [self addSubview:containView];
    //创建16个天气button
    for (NSInteger i = 0; i<16; i++) {
        BLButtonForWeatherSecondScrollView * scrBtn = [[BLButtonForWeatherSecondScrollView alloc]init];
        scrBtn.userInteractionEnabled = YES;
        [containView addSubview:scrBtn];
        [self bringSubviewToFront:scrBtn];
        scrBtn.tag = i;
        [self.btnArray addObject:scrBtn];
    }
}

-(void)layoutSubviews
{
    //!!!: 调用太频繁
    [super layoutSubviews];
    self.containView.frame = CGRectMake(0, 0, self.width / 6 *16, self.height);
    CGFloat width = BLScreenSize.width / 6;
    CGFloat height = BLScreenSize.height *0.6;
    CGFloat x = 0;
    CGFloat y = 0;
    for (NSInteger i = 0; i < self.self.btnArray.count; i++) {
        BLButtonForWeatherSecondScrollView *btn = self.btnArray[i];
        x = width  * i;
        btn.frame = CGRectMake(x, y, width, height);
        //        BLog(@"%ld ---- %@",i,NSStringFromCGPoint(btn.frame.origin));
    }
    
}



@end
